package com.cn.aam.checaiduo.backend.utils;

import com.orhanobut.logger.Logger;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okio.Buffer;

/**
 * Created by 艹羊 on 2017/5/25.
 */
public class NormalInterceptor implements Interceptor {


    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request()
                .newBuilder()
                .addHeader("Content-Type", "application/json;charset=UTF-8")
//                .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
//                .addHeader("Accept-Encoding", "gzip, deflate")
                .addHeader("Connection", "keep-alive")
//                .addHeader("User-Agent", "dreammove-android")
                .build();

        Logger.d("网络请求 " + request.toString());

        if ("POST".equals(request.method())) {
            Buffer buffer = new Buffer();
            request.body().writeTo(buffer);
            Logger.d("请求参数 " + buffer.readUtf8());
        }

        return chain.proceed(request);
    }
}